//go:build js || wasm

package godom

import (
	"syscall/js"
)

// HTMLCollectionWrapper
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection
type HTMLCollectionWrapper interface {
	JSWrapper

	Length() int

	Item(index int) js.Value
	NamedItem(name string) js.Value
}

type HTMLCollection struct {
	jsValue js.Value
}

func (h *HTMLCollection) Length() int {
	return h.jsValue.Get("length").Int()
}

func (h *HTMLCollection) Item(index int) js.Value {
	return h.jsValue.Call("item", index)
}

func (h *HTMLCollection) NamedItem(name string) js.Value {
	return h.jsValue.Call("namedItem", name)
}

func (h *HTMLCollection) JSValue() js.Value {
	return h.jsValue
}
